{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "ee.Initialize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geetools import tools, ui, collection, utils"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ipygee as ui"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get a NDVI Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "l8 = collection.Landsat8SR()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = ee.Geometry.Point([-72,-42])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "col = l8.collection.filterBounds(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = ee.Image(col.first())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "ndvi = l8.ndvi(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get point grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "points = ndvi.sample(scale=10000, geometries=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Linear Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "d = tools.image.linearFunction(ndvi, 'ndvi', mean=0.3, range_min=0, range_max=1, min=2, max=5)\n",
    "result = ndvi.addBands(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "chart = ui.chart.Image.bandsByRegion(result, points.limit(100), xProperty='ndvi')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Gauss Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "gauss = tools.image.gaussFunction(ndvi, 'ndvi', 0, 1, mean=0.3, output_min=0, output_max=1, stretch=2)\n",
    "gauss = ndvi.addBands(gauss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "chart_gauss = ui.chart.Image.bandsByRegion(gauss, points.limit(100), xProperty='ndvi', bands=['gauss'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d9e251e6b8df4f80a417617103d2e14c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HTML(value='<embed src=data:image/svg+xml;charset=utf-8;base64,PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0ndXRmLTg…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "chart_gauss.renderWidget(width=800)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Normal Distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "normal = tools.image.normalDistribution(ndvi, 'ndvi', scale=30, maxPixels=1e13)\n",
    "result_n = ndvi.addBands(normal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "chart_normal = ui.chart.Image.bandsByRegion(result_n, points.limit(100), xProperty='ndvi', bands=['normal_distribution'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Charts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "charts = chart.cat(chart_gauss, chart_normal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1a5c570529764eab9f102c03dae1262a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HTML(value='<embed src=data:image/svg+xml;charset=utf-8;base64,PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0ndXRmLTg…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "charts.renderWidget(width=800)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>normal_distribution</th>\n",
       "      <th>gauss</th>\n",
       "      <th>linear_function</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>-0.264706</th>\n",
       "      <td>0.499408</td>\n",
       "      <td>0.005691</td>\n",
       "      <td>0.193277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-0.088890</th>\n",
       "      <td>0.567368</td>\n",
       "      <td>0.088583</td>\n",
       "      <td>0.444442</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-0.078514</th>\n",
       "      <td>0.570398</td>\n",
       "      <td>0.100673</td>\n",
       "      <td>0.459266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-0.003532</th>\n",
       "      <td>0.588462</td>\n",
       "      <td>0.228679</td>\n",
       "      <td>0.566383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-0.000902</th>\n",
       "      <td>0.588968</td>\n",
       "      <td>0.234580</td>\n",
       "      <td>0.570140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>-0.000405</th>\n",
       "      <td>0.589063</td>\n",
       "      <td>0.235707</td>\n",
       "      <td>0.570850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.000149</th>\n",
       "      <td>0.589168</td>\n",
       "      <td>0.236966</td>\n",
       "      <td>0.571641</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.000299</th>\n",
       "      <td>0.589197</td>\n",
       "      <td>0.237309</td>\n",
       "      <td>0.571856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.000335</th>\n",
       "      <td>0.589204</td>\n",
       "      <td>0.237391</td>\n",
       "      <td>0.571908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.001249</th>\n",
       "      <td>0.589376</td>\n",
       "      <td>0.239480</td>\n",
       "      <td>0.573213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.001432</th>\n",
       "      <td>0.589410</td>\n",
       "      <td>0.239900</td>\n",
       "      <td>0.573474</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.001649</th>\n",
       "      <td>0.589451</td>\n",
       "      <td>0.240398</td>\n",
       "      <td>0.573784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.002603</th>\n",
       "      <td>0.589630</td>\n",
       "      <td>0.242598</td>\n",
       "      <td>0.575147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.002661</th>\n",
       "      <td>0.589640</td>\n",
       "      <td>0.242732</td>\n",
       "      <td>0.575229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.003678</th>\n",
       "      <td>0.589829</td>\n",
       "      <td>0.245092</td>\n",
       "      <td>0.576683</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.003924</th>\n",
       "      <td>0.589875</td>\n",
       "      <td>0.245666</td>\n",
       "      <td>0.577034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.003950</th>\n",
       "      <td>0.589880</td>\n",
       "      <td>0.245727</td>\n",
       "      <td>0.577072</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.004020</th>\n",
       "      <td>0.589893</td>\n",
       "      <td>0.245888</td>\n",
       "      <td>0.577171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.004252</th>\n",
       "      <td>0.589935</td>\n",
       "      <td>0.246431</td>\n",
       "      <td>0.577503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.005187</th>\n",
       "      <td>0.590107</td>\n",
       "      <td>0.248622</td>\n",
       "      <td>0.578839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.005596</th>\n",
       "      <td>0.590182</td>\n",
       "      <td>0.249584</td>\n",
       "      <td>0.579423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.006387</th>\n",
       "      <td>0.590326</td>\n",
       "      <td>0.251451</td>\n",
       "      <td>0.580553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.006695</th>\n",
       "      <td>0.590382</td>\n",
       "      <td>0.252180</td>\n",
       "      <td>0.580993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.007015</th>\n",
       "      <td>0.590440</td>\n",
       "      <td>0.252939</td>\n",
       "      <td>0.581450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.007594</th>\n",
       "      <td>0.590544</td>\n",
       "      <td>0.254317</td>\n",
       "      <td>0.582277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.007887</th>\n",
       "      <td>0.590597</td>\n",
       "      <td>0.255015</td>\n",
       "      <td>0.582695</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.008090</th>\n",
       "      <td>0.590633</td>\n",
       "      <td>0.255500</td>\n",
       "      <td>0.582985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.008691</th>\n",
       "      <td>0.590741</td>\n",
       "      <td>0.256941</td>\n",
       "      <td>0.583845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.008852</th>\n",
       "      <td>0.590770</td>\n",
       "      <td>0.257326</td>\n",
       "      <td>0.584074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.009524</th>\n",
       "      <td>0.590889</td>\n",
       "      <td>0.258943</td>\n",
       "      <td>0.585034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.071252</th>\n",
       "      <td>0.599338</td>\n",
       "      <td>0.432692</td>\n",
       "      <td>0.673217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.073347</th>\n",
       "      <td>0.599536</td>\n",
       "      <td>0.439355</td>\n",
       "      <td>0.676210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.078431</th>\n",
       "      <td>0.599990</td>\n",
       "      <td>0.455685</td>\n",
       "      <td>0.683473</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.079324</th>\n",
       "      <td>0.600066</td>\n",
       "      <td>0.458575</td>\n",
       "      <td>0.684748</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.093040</th>\n",
       "      <td>0.601100</td>\n",
       "      <td>0.503735</td>\n",
       "      <td>0.704343</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.131690</th>\n",
       "      <td>0.602629</td>\n",
       "      <td>0.635415</td>\n",
       "      <td>0.759557</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.148372</th>\n",
       "      <td>0.602655</td>\n",
       "      <td>0.692094</td>\n",
       "      <td>0.783388</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.163030</th>\n",
       "      <td>0.602362</td>\n",
       "      <td>0.740587</td>\n",
       "      <td>0.804328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.163730</th>\n",
       "      <td>0.602340</td>\n",
       "      <td>0.742860</td>\n",
       "      <td>0.805329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.183406</th>\n",
       "      <td>0.601464</td>\n",
       "      <td>0.804444</td>\n",
       "      <td>0.833436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.210970</th>\n",
       "      <td>0.599348</td>\n",
       "      <td>0.880845</td>\n",
       "      <td>0.872815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.231262</th>\n",
       "      <td>0.597133</td>\n",
       "      <td>0.927160</td>\n",
       "      <td>0.901803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.289177</th>\n",
       "      <td>0.587810</td>\n",
       "      <td>0.998127</td>\n",
       "      <td>0.984538</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.304052</th>\n",
       "      <td>0.584716</td>\n",
       "      <td>0.999737</td>\n",
       "      <td>0.994211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.309353</th>\n",
       "      <td>0.583546</td>\n",
       "      <td>0.998601</td>\n",
       "      <td>0.986639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.311333</th>\n",
       "      <td>0.583100</td>\n",
       "      <td>0.997946</td>\n",
       "      <td>0.983810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.356125</th>\n",
       "      <td>0.571734</td>\n",
       "      <td>0.950829</td>\n",
       "      <td>0.919821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.368159</th>\n",
       "      <td>0.568274</td>\n",
       "      <td>0.928336</td>\n",
       "      <td>0.902630</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.392541</th>\n",
       "      <td>0.560761</td>\n",
       "      <td>0.871902</td>\n",
       "      <td>0.867799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.404762</th>\n",
       "      <td>0.556748</td>\n",
       "      <td>0.838889</td>\n",
       "      <td>0.850340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.594141</th>\n",
       "      <td>0.476876</td>\n",
       "      <td>0.250204</td>\n",
       "      <td>0.579799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.600000</th>\n",
       "      <td>0.473977</td>\n",
       "      <td>0.236627</td>\n",
       "      <td>0.571429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.715237</th>\n",
       "      <td>0.413778</td>\n",
       "      <td>0.063002</td>\n",
       "      <td>0.406805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.717579</th>\n",
       "      <td>0.412508</td>\n",
       "      <td>0.061054</td>\n",
       "      <td>0.403458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.771096</th>\n",
       "      <td>0.383210</td>\n",
       "      <td>0.028316</td>\n",
       "      <td>0.327006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.797962</th>\n",
       "      <td>0.368387</td>\n",
       "      <td>0.018535</td>\n",
       "      <td>0.288626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.800728</th>\n",
       "      <td>0.366860</td>\n",
       "      <td>0.017717</td>\n",
       "      <td>0.284674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.837381</th>\n",
       "      <td>0.346635</td>\n",
       "      <td>0.009458</td>\n",
       "      <td>0.232313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.864023</th>\n",
       "      <td>0.331999</td>\n",
       "      <td>0.005767</td>\n",
       "      <td>0.194253</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.879007</th>\n",
       "      <td>0.323809</td>\n",
       "      <td>0.004290</td>\n",
       "      <td>0.172847</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>97 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           normal_distribution     gauss  linear_function\n",
       "-0.264706             0.499408  0.005691         0.193277\n",
       "-0.088890             0.567368  0.088583         0.444442\n",
       "-0.078514             0.570398  0.100673         0.459266\n",
       "-0.003532             0.588462  0.228679         0.566383\n",
       "-0.000902             0.588968  0.234580         0.570140\n",
       "-0.000405             0.589063  0.235707         0.570850\n",
       " 0.000149             0.589168  0.236966         0.571641\n",
       " 0.000299             0.589197  0.237309         0.571856\n",
       " 0.000335             0.589204  0.237391         0.571908\n",
       " 0.001249             0.589376  0.239480         0.573213\n",
       " 0.001432             0.589410  0.239900         0.573474\n",
       " 0.001649             0.589451  0.240398         0.573784\n",
       " 0.002603             0.589630  0.242598         0.575147\n",
       " 0.002661             0.589640  0.242732         0.575229\n",
       " 0.003678             0.589829  0.245092         0.576683\n",
       " 0.003924             0.589875  0.245666         0.577034\n",
       " 0.003950             0.589880  0.245727         0.577072\n",
       " 0.004020             0.589893  0.245888         0.577171\n",
       " 0.004252             0.589935  0.246431         0.577503\n",
       " 0.005187             0.590107  0.248622         0.578839\n",
       " 0.005596             0.590182  0.249584         0.579423\n",
       " 0.006387             0.590326  0.251451         0.580553\n",
       " 0.006695             0.590382  0.252180         0.580993\n",
       " 0.007015             0.590440  0.252939         0.581450\n",
       " 0.007594             0.590544  0.254317         0.582277\n",
       " 0.007887             0.590597  0.255015         0.582695\n",
       " 0.008090             0.590633  0.255500         0.582985\n",
       " 0.008691             0.590741  0.256941         0.583845\n",
       " 0.008852             0.590770  0.257326         0.584074\n",
       " 0.009524             0.590889  0.258943         0.585034\n",
       "...                        ...       ...              ...\n",
       " 0.071252             0.599338  0.432692         0.673217\n",
       " 0.073347             0.599536  0.439355         0.676210\n",
       " 0.078431             0.599990  0.455685         0.683473\n",
       " 0.079324             0.600066  0.458575         0.684748\n",
       " 0.093040             0.601100  0.503735         0.704343\n",
       " 0.131690             0.602629  0.635415         0.759557\n",
       " 0.148372             0.602655  0.692094         0.783388\n",
       " 0.163030             0.602362  0.740587         0.804328\n",
       " 0.163730             0.602340  0.742860         0.805329\n",
       " 0.183406             0.601464  0.804444         0.833436\n",
       " 0.210970             0.599348  0.880845         0.872815\n",
       " 0.231262             0.597133  0.927160         0.901803\n",
       " 0.289177             0.587810  0.998127         0.984538\n",
       " 0.304052             0.584716  0.999737         0.994211\n",
       " 0.309353             0.583546  0.998601         0.986639\n",
       " 0.311333             0.583100  0.997946         0.983810\n",
       " 0.356125             0.571734  0.950829         0.919821\n",
       " 0.368159             0.568274  0.928336         0.902630\n",
       " 0.392541             0.560761  0.871902         0.867799\n",
       " 0.404762             0.556748  0.838889         0.850340\n",
       " 0.594141             0.476876  0.250204         0.579799\n",
       " 0.600000             0.473977  0.236627         0.571429\n",
       " 0.715237             0.413778  0.063002         0.406805\n",
       " 0.717579             0.412508  0.061054         0.403458\n",
       " 0.771096             0.383210  0.028316         0.327006\n",
       " 0.797962             0.368387  0.018535         0.288626\n",
       " 0.800728             0.366860  0.017717         0.284674\n",
       " 0.837381             0.346635  0.009458         0.232313\n",
       " 0.864023             0.331999  0.005767         0.194253\n",
       " 0.879007             0.323809  0.004290         0.172847\n",
       "\n",
       "[97 rows x 3 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "charts.dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
